{extend name="public:_index" /}
{block name="title"}文章管理{/block}
{block name="description"}描述{/block}
{block name="keywords"}关键词{/block}
{block name="plugins_css"}
<link href="/static/back/plugins/forms/togglebutton/toggle-buttons.css" type="text/css" rel="stylesheet" />
{/block}
{block name="heading"}文章{/block}
{block name="breadcrumb"}文章{/block}
{block name="wrapper"}
<div class="col-lg-12">
    <div class="">
        <a class="btn btn-default" href="{:url('back/Article/add')}">
            <span class="icon16 entypo-icon-plus-2"></span>
            添加文章
        </a>
        <div class="marginB10"></div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4>
                <span class="icon16 icomoon-icon-numbered-list"></span>
                <span>文章列表</span>
            </h4>
            <a href="#" class="minimize" style="display: none;">Minimize</a>
        </div>
        <div class="panel-body noPad">
            <div class="responsive" tabindex="5005" style="overflow: hidden; outline: none;">
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>封面</th>
                        <th>标题</th>
                        <th>状态</th>
                        <th>阅读数量</th>
                        <th>评论数量</th>
                        <th>作者</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="articles" id="vo"}

                    <tr>
                        <td>{$vo.id}</td>
                        <td>
                            <div class="internal_page_item internal_page_item_gallery">
                                <div class="overlay_a img-thumbnail">
                                    <img src="{if condition="$vo.image AND $vo.image.type neq 3"}{$vo.image.url}{else/}/images/default.png{/if}" alt="0092" title="0092" class="img-box-img-cover">
                                    <div class="overlay">
                                        <a class="overlay_img cboxElement" href="{if condition="$vo.image AND $vo.image.type neq 3"}{$vo.image.url}{else/}/images/default.png{/if}" rel="lightbox" title=""></a>
                                        <a class="overlay_project" href="javascript:void(0);" onclick="image_upload('上传图片', '{:url('back/Image/upload', ['table'=>'article','tid'=>$vo['id'], 'pid'=>1])}', '650', '526');"></a>
                                    </div>
                                </div>
                            </div>
                        </td>
                        <td>{$vo.title}</td>
                        <td>
                            <div class="center marginR10">
                                <div class="iToggle-button">
                                    <input type="checkbox" class="nostyle" data-id="{$vo.id}" {$vo.status=='publish'?'checked="checked"':''} >
                                </div>
                            </div>
                        </td>
                        <td>{$vo.read_count}</td>
                        <td>{:count($vo.comments)}</td>
                        <td>{$vo.user.nickname}</td>
                        <td style="width:100px;">
                            <div class="controls center">
                                <a href="{:url('back/Article/edit', ['id'=>$vo['id']])}" class="tip" title="编辑">
                                    <span class="icon12 icomoon-icon-pencil"></span>
                                </a>
                                <a href="javascript:void(0);" class="tip" onclick="article_del(this, '{$vo.id}')" oldtitle="Remove task" title="删除" data-hasqtip="true">
                                    <span class="icon12 icomoon-icon-remove"></span>
                                </a>
                                <a href="{:url('index/Index/article', ['id'=>$vo['id']])}" class="tip" title="访问链接" data-hasqtip="true" target="_blank">
                                    <span class="icon12 entypo-icon-network"></span>
                                </a>
                            </div>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>

            <div class="paginate-div" {$page?'style="margin-top:20px;"':''}>
                {$page}
            </div>
        </div>
    </div><!-- End .panel -->
</div>
{/block}

{block name="plugins_js"}

<script type="text/javascript" src="/static/back/js/common.js"></script>
<script type="text/javascript" src="/static/back/plugins/layer/layer.js"></script>
<script type="text/javascript" src="/static/back/plugins/forms/togglebutton/jquery.toggle.buttons.js"></script>
<script type="text/javascript" src="/static/home/js/jquery.colorbox-min.js"></script>
<script type="text/javascript" src="/static/home/js/jquery.custom.js"></script>

<script>

    /**
     * 图片上传
     * @param title
     * @param url
     * @param w
     * @param h
     */
    function image_upload(title, url, w, h){
        layer_show(title, url, w, h);
    }

    /**
     * 编辑文章
     * @param title
     * @param url
     * @param w
     * @param h
     */
    function article_edit(title, url, w, h){
        layer_show(title, url, w, h);
    }

    /**
     * 删除文章
     * @param obj
     * @param id
     */
    function article_del(obj, id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                data: {
                    id: id
                },
                url: '/admin/article/delete.html',
                dataType: 'json',
                success: function(response){
                    if (response.status == 'success') {
                        $(obj).parents("tr").remove();
                        layer.msg('删除成功!',{icon:1,time:1000});
                    } else if ( response.status == 'failed') {
                        layer.msg('删除失败', {icon:2,time:1000});
                    }
                },
                error:function(data) {
                    layer.msg('请求失败!',{icon:2,time:1000});
                    console.log(data.msg);
                },
            });
        });
    }
</script>

<script>
    $(document).ready(function() {
        $('.iToggle-button').toggleButtons({
            width: 70,
            label: {
                enabled: "<span class='icon16 icomoon-icon-checkmark white'></span>",
                disabled: "<span class='icon16 icomoon-icon-close white marginL10'></span>"
            }
        });

        /**
         * 更改状态
         */
        $('.iToggle-button input').change(function(){
            var status = $(this)[0].checked ? 'publish' : 'save';
            $.ajax({
                type: 'POST',
                data: {
                    id: $(this).data('id'),
                    status: status
                },
                url: '/admin/article/change_status.html',
                dataType: 'json',
                success: function(response){
                    if (response.status == 'success') {
                        layer.msg('修改成功!',{icon:1,time:1000});
                    } else if ( response.status == 'failed') {
                        layer.msg('修改失败', {icon:2,time:1000});
                    }
                },
                error:function(data) {
                    layer.msg('请求失败!',{icon:2,time:1000});
                    console.log(data.msg);
                },
            });
        });

    });

</script>

{/block}